<template>
	<view class="city">
		<missthee-indexlist :data="list" @select-item='selectHandler'></missthee-indexlist>
		
		<u-picker mode="selector" v-model="show" :range="list_area" range-key="regionName" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:[],
				
				list:{
					"A":[],
					"B":[],
					"C":[],
					"D":[],
					"E":[],
					"F":[],
					"G":[],
					"H":[],
					"I":[],
					"G":[],
					"K":[],
					"L":[],
					"M":[],
					"N":[],
					"O":[],
					"P":[],
					"Q":[],
					"R":[],
					"S":[],
					"T":[],
					"U":[],
					"V":[],
					"W":[],
					"X":[],
					"Y":[],
					"Z":[],
				},
				
				show:false,
				
				
				list_area:[],
				info:'',
			}
		},
		methods: {
			getList(){
				this.request.httpTokenRequest({
					url: "movie/getAllCity",
					method: "get"
				}, {}).then(res => {
					if (res.code == 0) {
						this.data = res.data
						this.arrSort()
					}else {
						this.$util.msg(res.msg)
					}
				}, error => {})
			},
			arrSort(){
				for(let key in this.list){
					this.data.forEach(item=>{
						if(item.initials == key){
							item['name'] = item['cityName']; // 添加新的键值对
							item['customParam'] = {
								"id": item.id,
								"cityCode":  item.cityCode,
								"cityName":  item.cityName,
								"cityPinYin":  item.cityPinYin,
								"isHot":  item.isHot,
								"initials": item.initials
							}
							item['name'] = item['cityName']; // 添加新的键值对
							delete item['cityCode']; // 删除旧的键值对
							delete item['cityName']; // 删除旧的键值对
							delete item['cityPinYin']; // 删除旧的键值对
							delete item['isHot']; // 删除旧的键值对
							delete item['initials']; // 删除旧的键值对
							this.list[key].push(item)
						}
					})
				}
			},
			selectHandler(e){
				this.info =e.customParam
				this.request.httpTokenRequest({
					url: "movie/getCityRegions",
					method: "get"
				}, {
					cityCode:e.customParam.cityCode
				}).then(res => {
					if (res.code == 0) {
						this.list_area = res.data
						this.show = true
					}else {
						this.$util.msg(res.msg)
					}
				}, error => {})
				// uni.navigateBack()
			},
			confirm(e){
				this.info.regionCode = this.list_area[e].regionCode
				this.info.regionName = this.list_area[e].regionName
				uni.setStorageSync('movieLocation',this.info)
				uni.navigateBack()
			},
		},
		onLoad() {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.city {
		min-height: 100vh;
	}
</style>
